#ifndef _KLIGHT_MODULE_
#define _KLIGHT_MODULE_

#include "light.h"

typedef struct
{
    void *pMSG;
    unsigned int MsgLen;
    unsigned char from;
}MSG_t; 

typedef struct
{ 
   char *name;
   
   /* operation of all */
   Ops_t *Operations;
   
   /* power operation */
   PM_Ops_t *PM_Operations;
   
   /*module number*/
   unsigned char MoudleId;
   
   /*flow state*/
   unsigned char state;
   
   /* msg of module */
   MSG_t ModMsg[32];
   
}MODULE_t, MODULE;
 

extern void module_init_ops(MODULE_t *mod, Ops_t *);
extern void module_init_pm_ops(MODULE_t *mod, PM_Ops_t *);
extern int insmod(MODULE_t *mod);
extern int rmmod(MODULE_t *);

extern int post_msg(int pid, void *msg, unsigned int );
extern int get_msg(MODULE *mod, MSG_t *msg);

#define module_init(x) static MODULE x##_module;\
                   static Ops_t x##_ops;\
      void x##()\
      {\
          x##_ops.light_init = x##_init;\
          x##_ops.light_run = x##_run;\
          x##_ops.light_close = x##_close;\
          module_init_ops(&(x##_module), &x##_ops);\
          x##_module.name = #x;\
          insmod(&(x##_module));\
      }
#endif